#ifndef _DUALRAM_H
#define _DUALRAM_H


#include <sys/time.h>
///////////
#define ARM2DSP_BASE_BYTES       8
#define ARM2DSP_head_BYTES       ARM2DSP_BASE_BYTES
#define ARM2DSP_CHANGABLE_BYTE1  16
#define ARM2DSP_CHNAGABLE_SIZE1  4
#define ARM2DSP_CHANGABLE_BYTE2  48
#define ARM2DSP_CHANGABLE_SIZE2  104//80
#define ARM2DSP_CHANGABLE_BYTE3  36
#define ARM2DSP_CHNAGABLE_SIZE3  4

#define ARM2DSP_STOP_BYTE        126
#define ARM2DSP_YARN_UP          0x01
#define ARM2DSP_YARN_DOWN        0x02
#define ARM2DSP_STOP_BIT         0x04
#define ARM2DSP_ZERO_BIT         0x08
#define ARM2DSP_STOPLINE_BIT     0x10
#define ARM2DSP_INCHRUN_BIT      0x20
#define ARM2DSP_RIBRUN_BIT       0x40
#define ARM2DSP_MUTE_BIT         0x80

#define ARM2DSP_SPEC_BYTE        18
#define ARM2DSP_SCISS_ONE        0x01
#define ARM2DSP_SCISS_TWO        0x02
#define ARM2DSP_QDB_RAISE        0x04
#define ARM2DSP_DROP_CLOTH       0x08
#define ARM2DSP_LOCK_MAC         0x10
#define ARM2DSP_FORBID_RUN       0x20
#define ARM2DSP_RUN_AFTER_ALARM  0x40
#define ARM2DSP_QDB_RESTART      0x80

#define ARM2DSP_SSHA_BYTE        88

#define KERNEL_NEW                   1

#if KERNEL_NEW
/*************ioctl相关的命令定义******************END*/
#include <linux/major.h>
#ifndef ATSHA204_MAJOR
#define ATSHA204_MAJOR 251
#endif

#ifndef DPRAM_IDT7132_MAJOR
#define DPRAM_IDT7132_MAJOR 252
#endif
//产品型号，字符串：CORE-RT9G45_DSP2812_V1.1-2012-12
#define PNAME_SLOT   _IOWR(ATSHA204_MAJOR, 2, int)
//客户ID，字符串：CID-VIP-0000-0000-0000-0001-SHMH
#define CID_SLOT   _IOWR(ATSHA204_MAJOR, 4, int)
//产品ID，字符串：PID-OEM-RTCHIP-0000-0000-0000-01
#define PID_SLOT   _IOWR(ATSHA204_MAJOR, 6, int)
//产品唯一序列号(研智编号，全球唯一)，字符串：UID-0000-0000-0000-0000-0000-001
#define UID_SLOT   _IOWR(ATSHA204_MAJOR, 8, int)
//加密IC本身的序列号(固件ID，全球唯一)
/*返回的32字节里只有前面13个字节有效，其中4-7是atmel保留字无用，客户只需要使用0~3和8~12即可
Byte#  Name  Description
0 - 3  SN[0:3]  Part of the serial number value.
4 - 7  RevNum  Chip revision number.
8 - 12  SN[4:8]   Part of the serial number value.
*/
#define FIRMWARE_SN   _IOWR(ATSHA204_MAJOR, 20, int)
//每个SLOT大小32个字节，每次只能整个32字节读写
#define CONFIG_SLOT_SIZE 32
//系统配置区域
#define SYS_CONFIG_SLOT   _IOWR(ATSHA204_MAJOR, 9, int)
//开放2个区，每个区32个字节的配置区域给用户,可以保存配置或进行加密
#define USER_CONFIG_SLOT1   _IOWR(ATSHA204_MAJOR, 10, int)
#define USER_CONFIG_SLOT2   _IOWR(ATSHA204_MAJOR, 11, int)
//双口ram的命令定义
//双口RAM分区
#define DUAL_RAM_PARTION_TYPE_SYSREV             _IOWR(DPRAM_IDT7132_MAJOR, 0, int)
#define DUAL_RAM_PARTION_TYPE_DSP2ARM                _IOWR(DPRAM_IDT7132_MAJOR, 1, int)
#define DUAL_RAM_PARTION_TYPE_ARM2DSP                _IOWR(DPRAM_IDT7132_MAJOR, 2, int)
//LED控制
#define DUAL_RAM_CMD_LED                                     _IOWR(DPRAM_IDT7132_MAJOR, 3, int)
//LCD背光控制
#define LCD_POWER_CONTROL                                   _IOWR(DPRAM_IDT7132_MAJOR, 4, int)
#else
//开放2个区，每个区32个字节的配置区域给用户,可以保存配置或进行加密
#define USER_CONFIG_SLOT1			 		0x1A
#define USER_CONFIG_SLOT2			 		0x1B
#define FIRMWARE_SN                         0x20
//dual ram
#define DUAL_RAM_PARTION_TYPE_DSP2ARM    0x01
#define DUAL_RAM_PARTION_TYPE_ARM2DSP    0x02
#endif
//
#define SET_PNAME_SLOT(fd) ioctl((fd), PNAME_SLOT, 0)
#define SET_CID_SLOT(fd) ioctl((fd), CID_SLOT, 0)
#define SET_PID_SLOT(fd) ioctl((fd), PID_SLOT, 0)
#define SET_UID_SLOT(fd) ioctl((fd), UID_SLOT, 0)
#define SET_FIRMWARE_SN(fd) ioctl((fd), FIRMWARE_SN, 0)
#define SET_SYS_CONFIG_SLOT(fd) ioctl((fd), SYS_CONFIG_SLOT, 0)
#define SET_USER_CONFIG_SLOT1(fd) ioctl((fd), USER_CONFIG_SLOT1, 0)
#define SET_USER_CONFIG_SLOT2(fd) ioctl((fd), USER_CONFIG_SLOT2, 0)
#define SET_ARM2DSP(fd) ioctl(fd, DUAL_RAM_PARTION_TYPE_ARM2DSP, 0)
#define SET_DSP2ARM(fd) ioctl(fd, DUAL_RAM_PARTION_TYPE_DSP2ARM, 0)
//size
#define DSP2ARM_SIZE     128
#define ARM2DSP_SIZE     (2 * 1024 - 32 - 128)

//in[0]
#define MH_RUN               2
//in[1]
#define MH_RUN_RESET         1
#define MH_RUN_NORMAL        2
#define MH_RUN_GOONKNIT      3
#define MH_RUN_SETBEGIN      4
#define MH_RUN_DROPCLOTH     5
//send data to dsp
//#define MH_TEST              1
//in[0]
#define MH_TEST_JITOU        100
#define MH_TEST_JIJIA        101
#define MH_TEST_BOARD        102
#define MH_TEST_NEEDLE       103
#define MH_TEST_DSP          104
#define MH_TEST_I2C_READ     105
#define MH_TEST_I2C_SAVE     106
#define MH_GET_VERSION       248
#define MH_BOARDCOUNTERFK    249
#define MH_TEST_GETGOON      250
#define MH_TEST_SETPARAM     251
#define MH_TEST_GETPARAM     252
#define MH_BACK              253
#define MH_BOARDFK           254
#define MH_XHFK              255
//in[1]//for MH_TEST_GETGOON
#define MH_TEST_SETSIGN      0x80
#define MH_TEST_CONTINUEKNIT 0x40
#define MH_TEST_SETCAM       0x20
//in[1]
#define TEST_NONE            0
#define TEST_YARN            1
#define TEST_XZQ             2
#define TEST_SJDCT           3
#define TEST_DUMU            4
#define TEST_SINK            5
#define TEST_LED             8
#define TEST_JZJD            9
#define TEST_QDBSJ           10
#define TEST_QDBGZ           11
#define TEST_JITOU           15
#define TEST_ROCK            16
#define TEST_GLL             17
#define TEST_CLEARNEEDLE     18
#define TEST_GETNEEDLE       19
#define TEST_SETSTARTNEEDLE  20
#define TEST_SETENDNEEDLE    21
#define TEST_RESET_YARN      22
#define TEST_RESET_CAM       23
#define TEST_RESET_XZQ       24
#define TEST_RESET_DUMU      25
#define TEST_RESET_SINK      26
#define TEST_QDBSC           27
#define TEST_DUMU_RESTORE    28   //first reset then go to the gived value
#define TEST_CANCEL_SHAKE    29
#define TEST_SONGSHA_LEFT    30
#define TEST_SONGSHA_RIGHT   31
#define TEST_SONGSHA_ENABLE  32
#define TEST_CAM_MOTOR       33
#define TEST_RESET_CAM_MOTOR 34
#define TEST_RESET_CAM_DUMU  35
#define TEST_KAIHE_LOCK      36
#define TEST_ROLL            37
#define TEST_ROLL_LOCK       38
#define TEST_ROLL_OPEN       39
#define TEST_DSP2812_UPDATE  40

#define RESET_SJDCT          100
#define RESET_XZQ            101
#define RESET_YARN           102
#define RESET_DUMU           103
#define RESET_SINK           104
//get data from dsp
//out[0]
#define MH_SIGN_NEEDLE       1
#define MH_SIGN_JIJIA        2
#define MH_SIGN_JITOU        3
#define MH_SIGN_BOARD        4
//out[1]
#define MH_TEST_SIGN         (0xAA)


int com_init_data();
int com_exit_data();

int dualram_init();
void dualram_close();
void* Dualram_Cycle(void *arg);

typedef enum {
	DUALRAM_MH_TEST = 0,
	DUALRAM_MH_RUN = 1,
}DUALRAM_TYPE;

extern DUALRAM_TYPE dualram_type;


#define SYS_STATE_READY     1
#define SYS_STATE_RESET     2
#define SYS_STATE_KNIT      3
#define SYS_STATE_HALT      4

#endif
